﻿<%-- 
    Copyright (C) Binod Nepal, Planet Earth Solutions Pvt. Ltd., Kathmandu.
	Released under the terms of the GNU General Public License, GPL, 
	as published by the Free Software Foundation, either version 3 
	of the License, or (at your option) any later version.
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
    See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
--%>

<%@ Page Title="Manage Ads" Language="C#" MasterPageFile="~/Classifieds/Main.Master"
    AutoEventWireup="true" CodeBehind="ManageAds.aspx.cs" Inherits="MixNP.Web.Classifieds.MyAds" %>

<asp:Content ID="Content1" ContentPlaceHolderID="StyleSheetContentPlaceHolder" runat="server">
    <style type="text/css">
        
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ScriptsContentPlaceHolder" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="BodyContentPlaceHolder" runat="server">
    <asp:ScriptManager runat="server" />
    <h1>
        Manage Ads
    </h1>
    <hr class="hr" />
    <input type="button" onclick="location.href='/dashboard.mix';" value="Dashboard" />
    <asp:UpdateProgress ID="updProgress" runat="server">
        <ProgressTemplate>
            <div class="ajax-container">
                <img alt="progress" src="/spinner.gif" class="ajax-loader" />
            </div>
        </ProgressTemplate>
    </asp:UpdateProgress>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="AdsGridView" />
            <asp:AsyncPostBackTrigger ControlID="OldGridView" />
        </Triggers>
        <ContentTemplate>
            <h2>
                Current Ads
            </h2>
            <div id="no-ad" class="vpad8" style="display: none;">
                You do not have any recent ad.
                <a href='/my/ad.mix' title='Click Here to post an Ad'>
                    Click Here Post an Ad.
                </a>
            </div>
            <asp:GridView ID="AdsGridView" runat="server" AutoGenerateColumns="False" DataKeyNames="ItemId"
                DataSourceID="SqlDataSource1" AllowPaging="True" AllowSorting="True" EmptyDataText=""
                OnRowCommand="AdsGridView_RowCommand" OnRowDataBound="AdsGridView_RowDataBound">
                <Columns>
                    <asp:TemplateField HeaderText="" ItemStyle-Width="80">
                        <ItemTemplate>
                            <asp:ImageButton ID="EditImageButton" runat="server" ImageUrl="~/Resources/Images/edit.png"
                                ToolTip="I will edit this." CommandName="Modify" OnClientClick="return(confirm('Shall we edit this item?'));" />
                            <asp:ImageButton ID="SoldImageButton" runat="server" ImageUrl="~/Resources/Images/sold.png"
                                ToolTip="I sold it!" CommandName="Sold" OnClientClick="return(confirm('Yeppieee, you finally sold it! Was that true?\n\nHey Congratulations.'));" />
                            <asp:ImageButton ID="WithdrawImageButton" runat="server" ImageUrl="~/Resources/Images/withdraw.png"
                                ToolTip="I have changed my mind. Now want to withdraw this offer." CommandName="Withdraw"
                                OnClientClick="return(confirm('Even when an item is withdrawn, it will be visible on the website, but with a withdrawn flag.\n\nThis action is non reversible.\n\n Are you sure you want to withdraw this item?'));" />
                            <asp:ImageButton ID="RemoveImageButton" runat="server" ImageUrl="~/Resources/Images/remove.png"
                                ToolTip="I think I will remove this ad." CommandName="Remove" OnClientClick="return(confirm('Do you really want to remove this item?'));" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="ItemId" HeaderText="Id" ReadOnly="True" SortExpression="ItemId" />
                    <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                    <asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
                    <asp:BoundField DataField="CategoryName" HeaderText="Category" SortExpression="CategoryName" />
                    <asp:BoundField DataField="CityName" HeaderText="City" SortExpression="CityName" />
                    <asp:BoundField DataField="TotalViews" HeaderText="Hits" SortExpression="TotalViews" />
                    <asp:BoundField DataField="AddedOn" HeaderText="Added On" SortExpression="AddedOn" />
                </Columns>
            </asp:GridView>
            <h2>
                Expired Ads
            </h2>
            <div id="no-ad2" class="vpad8" style="display: none;">
                You do not have any expired ad.
                <a href='/my/ad.mix' title='Click Here to post an Ad'>
                    Click Here Post an Ad.
                </a>
            </div>
            <asp:GridView ID="OldGridView" runat="server" AutoGenerateColumns="False" DataKeyNames="ItemId"
                DataSourceID="SqlDataSource2" AllowPaging="True" AllowSorting="True" EmptyDataText=""
                OnRowCommand="OldGridView_RowCommand" OnRowDataBound="AdsGridView_RowDataBound">
                <Columns>
                    <asp:TemplateField HeaderText="" ItemStyle-Width="40">
                        <ItemTemplate>
                            <asp:ImageButton ID="OldRenewImageButton" runat="server" ImageUrl="~/Resources/Images/renew.png"
                                ToolTip="I will renew this ad." CommandName="Renew" OnClientClick="return(confirm('Do you really want to renew this ad?'));" />
                            <asp:ImageButton ID="OldRemoveImageButton" runat="server" ImageUrl="~/Resources/Images/remove.png"
                                ToolTip="I think I will remove this ad." CommandName="Withdraw" OnClientClick="return(confirm('Do you really want to remove this item?'));" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="ItemId" HeaderText="Id" ReadOnly="True" SortExpression="ItemId" />
                    <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                    <asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
                    <asp:BoundField DataField="ItemStatusName" HeaderText="Status" SortExpression="ItemStatusName" />
                    <asp:BoundField DataField="CategoryName" HeaderText="Category" SortExpression="CategoryName" />
                    <asp:BoundField DataField="CityName" HeaderText="City" SortExpression="CityName" />
                    <asp:BoundField DataField="TotalViews" HeaderText="Hits" SortExpression="TotalViews" />
                    <asp:BoundField DataField="AddedOn" HeaderText="Added On" SortExpression="AddedOn" />
                </Columns>
            </asp:GridView>
        </ContentTemplate>
    </asp:UpdatePanel>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:PESConnectionString %>"
        SelectCommand="SELECT * FROM [ItemView] WHERE ([EmailAddress] = @EmailAddress) AND ItemStatusId=0 AND DaysLeft >=0 ORDER BY AddedOn DESC">
        <SelectParameters>
            <asp:SessionParameter Name="EmailAddress" SessionField="UserId" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:PESConnectionString %>"
        SelectCommand="SELECT * FROM [ItemView] WHERE ([EmailAddress] = @EmailAddress) AND ItemStatusId<>0 OR DaysLeft < 0 ORDER BY AddedOn DESC">
        <SelectParameters>
            <asp:SessionParameter Name="EmailAddress" SessionField="UserId" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="ScriptsContentPlaceHolderBottom"
    runat="server">
    <script type="text/javascript">
        jQuery(document).ready(function () {
            $(".ajax-container").height($(document).height() + 100);
        }
        );        
    </script>
</asp:Content>
